#!/bin/bash
set -e

export TZ=UTC
export HOME=/remote/iosg/jenkins-2/bot-coin
source /remote/iosg/home/bot-coin/miniconda3/etc/profile.d/conda.sh
conda activate coin2_motion_env_migration

cd ~/jenkins/workspace/coin2_fastfeed/coin

{% for machine in settings.keys() -%}
mkdir -p {{log_dir}}/{{trading_date}}/{{machine}}
{% endfor -%}


NUM_PARALLEL="512"
parallel -j "${NUM_PARALLEL}" --joblog fastfeed-gen.log <<EOF
{% for setting in [priority_settings, settings] -%}
{% for machine in setting.keys() -%}
{% for mea in setting[machine].keys() -%}
{% for recipe in setting[machine][mea].keys() -%}
{% if 'norm' in setting[machine][mea][recipe].keys() -%}
{% for (norms,worker, driver_settings, start, duration, threads_num, job_id, pi_dir) in setting[machine][mea][recipe]['norm'] -%}
srun --cpu-bind=cores --job-name {{job_id}} -N1 -n1 --cpus-per-task 1 -l --exclusive catchsegv ../fastfeed-converter {% for driver_file in driver_settings -%} --driver={{driver_file}} {% endfor -%} --date {{trading_date}} --mea {{mea}} --norm {{norms}} --worker {{worker}} --recipe {{recipe}} --log-dir={{log_dir}} --start={{start}} --duration={{duration}} --threads={{threads_num}} {% if pi_dir -%} --pi-dir={{pi_dir}} {%- endif %}
{% endfor -%}
{% else -%}
{% for group in setting[machine][mea][recipe].keys() -%}
{% for (worker, driver_settings, start, duration, threads_num, job_id, pi_dir) in setting[machine][mea][recipe][group] -%}
srun --cpu-bind=cores --job-name {{job_id}} -N1 -n1 --cpus-per-task 1 -l --exclusive catchsegv ../fastfeed-converter {% for driver_file in driver_settings -%} --driver={{driver_file}} {% endfor -%} --date {{trading_date}} --mea {{mea}} --group {{group}} --worker {{worker}} --recipe {{recipe}} --log-dir={{log_dir}} --start={{start}} --duration={{duration}} --threads={{threads_num}} {% if pi_dir -%} --pi-dir={{pi_dir}} {%- endif %}
{% endfor -%}
{% endfor -%}
{% endif -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}

EOF
